import axios from 'axios';
import { requestBegin, requestEnd } from './actionCommon';
import { ordersUrl } from '../config/httpConfig';
// export const GET_ORDERS = 'GET_ORDERS';
export const ORDERS_RECEIVED = 'ORDERS_RECEIVED';
export const ORDERS_INIT = 'ORDERS_INIT';
axios.defaults.withCredentials = true;
export function getOrders (option) {
    return (dispatch) => {
        dispatch(requestBegin('isFetching'));
        return axios.get(ordersUrl, {
            params: option.query,
        })
            .then((res) => {
                dispatch(orderReceived({
                    list: res.data,
                }));
                dispatch(requestEnd('success'));
            })
            .catch(err => {
                if (err) {
                    dispatch(requestEnd('err'));
                }
            });
    };
}
export function orderReceived (data) {
    return {
        type: ORDERS_RECEIVED,
        orders: data.list,
    };
}
export function ordersInit (data) {
    return {
        type: ORDERS_INIT,
        orders: data,
    };
}
